<extend name="Base/base" />
<block name='head'>
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/kaoqin.css"/>
    <link rel="stylesheet" type="text/css" href="/Public/Admin/css/main.css"/>
    <style>
        .icon-date{
            background:url('/Public/Admin/images/date.png') no-repeat right center;
            width: 25px;
            height: 25px;
            position: absolute;
            top: 6px;
            right: 11px;
            cursor:pointer;
        }
    </style>
</block>
<block name="content" >
    <section class="layui-larry-box mian-page page-attendanceStatistics">
	<div class="larry-personal">
            <div class="layui-tab">
                <blockquote class="layui-elem-quote news_search">
                    <form method="get">
                        <div class="layui-inline">
                            <span class="btn-upload form-group">
                                <select name="dept_id" class="layui-input search_input" <if condition='$class eq 1'>style="width:100px;background:#e6e6e6;"<else />style="width:100px;</if> {$class == 1?'disabled':''}>
                                    <option value="">按部门</option>
                                    <foreach name="depts" item="dept">
                                        <option value="{$dept.dept_id}" {$dept_id == $dept['dept_id'] ? 'selected' : ''}>{$dept.dept_name}</option>
                                    </foreach>
                                </select>
                            </span>
                        </div>
                        <div class="layui-inline">
                            <span class="btn-upload form-group">
<!--                                <select name="time" class="layui-input search_input" style="width:100px">
                                    <option value="">按月份</option>
                                    <foreach name="days" item="day">
                                        <option value="{$day}" <if condition='$contime neq ""'>{$contime == $day ? 'selected' : ''}<else />{$currentDay == $day ? 'selected' : ''}</if>> {$day}</option>
                                    </foreach>
                                </select>-->
                                <i class='icon-date datepickerInput' id="diary_date"></i>
                                <input type="text" name="time" placeholder="" value="{$_GET['time']?$_GET['time']:date('Y-m-d')}" class="layui-input search_input">
                            </span>
                        </div>
                        <a class="layui-btn search_btn search" data-url="{:U('index')}" style="margin-left:10px;"> 查询</a>
                        <input type="hidden" name="p" value="1" />
                    </form>
                </blockquote>
                
                <div class="layui-tab-content larry-personal-body clearfix mylog-info-box tabRedefine layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li data-id='out' class="layui-this" style="margin-left:0px;">外出统计</li>
                        <li data-id='leave'>请假统计</li>
                        <li data-id='evection'>出差统计</li>
                        <!--<li data-id='overtime'>加班统计</li>-->
                    </ul>
                    <div class="layui-tab-item layui-field-box layui-show absence">
			<table class="layui-table setTabBg out" lay-skin="line">
                            <thead>
                                    <tr>
                                            <th>部门</th>
                                            <th>姓名</th>
                                            <!--<th>申请时间</th>-->
                                            <th width='20%'>外出原因</th>
                                            <th>外出日期</th>
                                            <th>外出时间</th>
                                            <th>归来时间</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                    </tr>
                            </thead>
                            <tbody>
                                <notempty>
                                    <foreach name='out' item='data'>
                                        <tr>
                                            <td>{$data.dept_name}</td>
                                            <td>{$data.user_name}</td>
                                            <!--<td>{$data.begin_time}</td>-->
                                            <td>{$data.out_type}</td>
                                            <td>{$data.out_date}</td>
                                            <td>{$data.out_time1}</td>
                                            <td>{$data.out_time2}</td>
                                            <td>
                                                <if condition="$data['end_time'] eq ''">
                                                    <font color='red'>待审批</font>
                                                <else />
                                                    <font color='green'>已结束</font>
                                                </if>
                                            </td>
                                            <td><span class="operationBtn delBtn" data-url="{:U('delAbsence',array('run_id'=>$data['run_id'],'type'=>'out'))}" onmouseover="layer.tips('删除', this,{tips:[1, '#2D4271'],time:500});"></span></td>
                                        <tr>
                                    </foreach>
                                </notempty>
                            </tbody>
			</table>
                    </div>
                    <div class="layui-block">共{$count}条数据</div>
                    <div class="larry-table-page clearfix">
                        <div id="page" class="page">{$page}</div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</block>
<block name="script">
    <script type="text/javascript" src="/Public/Admin/js/attend.js"></script>
    <script type="text/javascript" src="/Public/Admin/js/common.js"></script>
    <script type="text/javascript">
        $(initAttend());
        $(dateTime(3));
        $(".absence").delegate('.delBtn', 'click', function () {
            var url = $(this).attr('data-url');
            var type = url.substring(url.lastIndexOf('/')+1);
            if(type.indexOf('.')>0)
                type = type.substring(0,type.lastIndexOf('.'));

            var str=location.href; //取得整个地址栏
            var num=str.indexOf("?")
            str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]
            var arr=str.split("&"); //各个参数放到数组里
            var dept_id = arr[0].substring(arr[0].indexOf('=')+1);
            var time = arr[1].substring(arr[1].indexOf('=')+1);

            layer.confirm('确定删除该条记录吗？', {
                closeBtn: 0,
                btn: ['确定', '取消'] //按钮
            }, function () {
                var index = layer.load(1, {shade: false});
                $.get(url, function (res) {
    //                console.log(res);
                    if (res.status == 1) {
                        layer.msg('删除成功');

                        var url = 'absence/dept_id/'+dept_id+'/time/'+time+'/type/'+type+'/p/'+1;
                        $.ajax({
                            url: url,
                            type: 'get',
                            async: false,
                            success: function (res) {
                                console.log(res);
                                if(res.type == 'leave'){
                                    var html = '<table class="layui-table setTabBg out" lay-skin="line"><thead>';
                                    html += '<tr><th>部门</th><th>姓名</th><th>请假类型</th><th width="20%">请假原因</th><th>请假天数</th><th>开始日期</th><th>结束日期</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                                    if (res['data'].length > 0) {
                                        for (var i = 0; i < res['data'].length; i++) {
                                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                                            html += '<td>' + res['data'][i].user_name + '</td>';
                                            html += '<td>' + res['data'][i].leave_type2 + '</td>';
                                            html += '<td>' + res['data'][i].leave_type + '</td>';
                                            html += '<td>' + res['data'][i].leave_duration + '</td>';
                                            html += '<td>' + res['data'][i].leave_date1 + '</td>';
                                            html += '<td>' + res['data'][i].leave_date2 + '</td>';
                                            if(res['data'][i].end_time){
                                                html += '<td><font color="green">已结束</font></td>';
                                            }else{
                                                html += '<td><font color="red">待审批</font></td>';
                                            }
                                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/leave" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                                        }
                                    }
                                    html += '</tbody></table>';
                                    $('.absence').html(html);
                                    $('.layui-block').text('共'+res['count']+'条数据');
                //                    $('#page').html(res['pages']);
                                }else if(res.type == 'evection'){
                                    var html = '<table class="layui-table setTabBg evection" lay-skin="line"><thead>';
                                    html += '<tr><th>部门</th><th>姓名</th><th>出差地点</th><th width="30%">出差事由</th><th>开始日期</th><th>结束日期</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                                    if (res['data'].length > 0) {
                                        for (var i = 0; i < res['data'].length; i++) {
                                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                                            html += '<td>' + res['data'][i].user_name + '</td>';
                                            html += '<td>' + res['data'][i].evection_dest + '</td>';
                                            html += '<td title='+res['data'][i].reason+'>' + res['data'][i].reason.substring(0,45) + '...</td>';
                                            html += '<td>' + res['data'][i].evection_date1.substring(0,10) + '</td>';
                                            html += '<td>' + res['data'][i].evection_date2.substring(0,10) + '</td>';

                                            if(res['data'][i].end_time){
                                                html += '<td><font color="green">已结束</font></td>';
                                            }else{
                                                html += '<td><font color="red">待审批</font></td>';
                                            }
                                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/evection" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                                        }
                                    }
                                    html += '</tbody></table>';
                                    $('.absence').html(html);
                                    $('.layui-block').text('共'+res['count']+'条数据');
                //                    $('#page').html(res['pages']);
                                }else if(res.type == 'out'){
                                    var html = '<table class="layui-table setTabBg evection" lay-skin="line"><thead>';
                                    html += '<tr><th>部门</th><th>姓名</th><th width="20%">外出原因</th><th>外出日期</th><th>外出时间</th><th>归来时间</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                                    if (res['data'].length > 0) {
                                        for (var i = 0; i < res['data'].length; i++) {
                                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                                            html += '<td>' + res['data'][i].user_name + '</td>';
                                            html += '<td>' + res['data'][i].out_type + '</td>';
                                            html += '<td>' + res['data'][i].out_date + '</td>';
                                            html += '<td>' + res['data'][i].out_time1 + '</td>';
                                            html += '<td>' + res['data'][i].out_time2 + '</td>';
                                            if(res['data'][i].end_time){
                                                html += '<td><font color="green">已结束</font></td>';
                                            }else{
                                                html += '<td><font color="red">待审批</font></td>';
                                            }
                                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/out" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                                        }
                                    }
                                    html += '</tbody></table>';
                                    $('.absence').html(html);
                                    $('.layui-block').text('共'+res['count']+'条数据');
                //                    $('#page').html(res['pages']);
                                }
                            }
                        })
                        layer.close(index);
                    } else {
                        layer.msg('删除失败');
                    }
                })
            }, function (index) {
                layer.close(index);
            })
        })
    </script>
</block>